#include <stdio.h>
#include "Dump.h"
#include "Table.h"
#include "Pointers.h"
#include "Insert.h"

int LastPos;


#define PTR_01 0x20000

//
#define PTR_02 0x20106
#define PTR_03 0x20112
#define PTR_04 0x20148
#define PTR_05 0x2014E
#define PTR_06 0x20152
#define PTR_07 0x20154
#define PTR_08 0x20184
#define PTR_09 0x20186
#define PTR_10 0x20188
#define PTR_11 0x20194
#define PTR_12 0x20196
#define PTR_13 0x2019E
#define PTR_14 0x201F0
//
#define PTR_15 0x20252
#define PTR_16 0x20260
#define PTR_17 0x20262
#define PTR_18 0x20264
#define PTR_19 0x20266

#define PTR_START01 0x280B4

#define PTR_START02 0x28312
#define PTR_START03 0x28374

#define PTR_MTE   0x02FF80
#define PTR_MENUS01 0x0200A6
#define PTR_MENUS02 0x0200F2


int main(int argc, char* argv[])
{

	if(argc < 3)
	{
		printf("Uso: Ys3-Main -[d|i] <Nome Da Rom> <Tbl>\n");
		return 0;
	}

	if(!strcmp(argv[1],"-d"))
	{
		//bloco 01
		DumpScript(argv[2], argv[3], "Scripts/[Ys3]-Script01.txt", PTR_01, 0x53, 0xFC, 0x020000, 0x8000 );

		DumpScript(argv[2], argv[3], "Scripts/[Ys3]-Menus01.txt", PTR_MENUS01, 0x25, 0xFC, 0x020000, 0x8000 );
		DumpScript(argv[2], argv[3], "Scripts/[Ys3]-Menus02.txt", PTR_MENUS02, 0x0A, 0xFC, 0x020000, 0x8000 );
		//

		DumpScript(argv[2], argv[3], "Scripts/[Ys3]-Script02.txt", PTR_02, 0x06, 0xFD, 0x020000, 0x8000 );
		DumpScript(argv[2], argv[3], "Scripts/[Ys3]-Script03.txt", PTR_03, 0x1B, 0xFD, 0x020000, 0x8000 );
		DumpScript(argv[2], argv[3], "Scripts/[Ys3]-Script04.txt", PTR_04, 0x03, 0xFD, 0x020000, 0x8000 );
		DumpScript(argv[2], argv[3], "Scripts/[Ys3]-Script05.txt", PTR_05, 0x02, 0xFD, 0x020000, 0x8000 );
		DumpScript(argv[2], argv[3], "Scripts/[Ys3]-Script06.txt", PTR_06, 0x01, 0xFD, 0x020000, 0x8000 );
	    DumpScript(argv[2], argv[3], "Scripts/[Ys3]-Script07.txt", PTR_07, 0x18, 0xFF, 0x020000, 0x8000 );
		DumpScript(argv[2], argv[3], "Scripts/[Ys3]-Script08.txt", PTR_08, 0x01, 0xFD, 0x020000, 0x8000 );
		DumpScript(argv[2], argv[3], "Scripts/[Ys3]-Script09.txt", PTR_09, 0x01, 0xFD, 0x020000, 0x8000 );
		DumpScript(argv[2], argv[3], "Scripts/[Ys3]-Script10.txt", PTR_10, 0x06, 0xFD, 0x020000, 0x8000 );
		DumpScript(argv[2], argv[3], "Scripts/[Ys3]-Script11.txt", PTR_11, 0x01, 0xFD, 0x020000, 0x8000 );
		DumpScript(argv[2], argv[3], "Scripts/[Ys3]-Script12.txt", PTR_12, 0x04, 0xFF, 0x020000, 0x8000 );
		DumpScript(argv[2], argv[3], "Scripts/[Ys3]-Script13.txt", PTR_13, 0x29, 0xFD, 0x020000, 0x8000 );
		DumpScript(argv[2], argv[3], "Scripts/[Ys3]-Script14.txt", PTR_14, 0x30, 0xFD, 0x020000, 0x8000 );
		DumpScript(argv[2], argv[3], "Scripts/[Ys3]-Script15.txt", PTR_15, 0x07, 0xFD, 0x020000, 0x8000 );
		DumpScript(argv[2], argv[3], "Scripts/[Ys3]-Script16.txt", PTR_16, 0x01, 0xFD, 0x020000, 0x8000 );
		DumpScript(argv[2], argv[3], "Scripts/[Ys3]-Script17.txt", PTR_17, 0x01, 0xFD, 0x020000, 0x8000 );
		DumpScript(argv[2], argv[3], "Scripts/[Ys3]-Script18.txt", PTR_18, 0x01, 0xFD, 0x020000, 0x8000 );
		DumpScript(argv[2], argv[3], "Scripts/[Ys3]-Script19.txt", PTR_19, 0x01, 0xFD, 0x020000, 0x8000 );
		//Textos principais
		DumpScript(argv[2], argv[3], "Scripts/[Ys3]-Text-01.txt", PTR_START01, 0x128, 0xFF, 0x020000, 00 );
		DumpScript(argv[2], argv[3], "Scripts/[Ys3]-Text-02.txt", PTR_START02, 0x30,  0xFF, 0x020000, 00 );
		DumpScript(argv[2], argv[3], "Scripts/[Ys3]-Text-03.txt", PTR_START03, 0x50,  0xFF, 0x020000, 00 );
		//tbl de mtes
		DumpScript(argv[2], "Tabelas/Ys3-Static-En.tbl", "Scripts/[Ys3]-MteTable.txt", PTR_MTE, 0x1E, 0xFF, 0x020000, 0x00 );
	}
	else if(!strcmp(argv[1],"-i"))
	{
		//bloco 01
	    InsertScript("Scripts/[Ys3]-Script01.txt", argv[3], argv[2], PTR_01, 0x2026A, 0x8000, 0xFC, 0x53);
		InsertScript("Scripts/[Ys3]-Menus01.txt", argv[3], argv[2], PTR_MENUS01, LastPos, 0x8000, 0xFC, 0X25);
		InsertScript("Scripts/[Ys3]-Menus02.txt", argv[3], argv[2], PTR_MENUS02, LastPos, 0x8000, 0xFC, 0x0A);
		InsertScript("Scripts/[Ys3]-Script02.txt", argv[3], argv[2], PTR_02, LastPos, 0x8000, 0xFD, 0x06);
		InsertScript("Scripts/[Ys3]-Script03.txt", argv[3], argv[2], PTR_03, LastPos, 0x8000, 0xFD, 0x1b);
		InsertScript("Scripts/[Ys3]-Script04.txt", argv[3], argv[2], PTR_04, LastPos, 0x8000, 0xFD, 0x03);
		InsertScript("Scripts/[Ys3]-Script05.txt", argv[3], argv[2], PTR_05, LastPos, 0x8000, 0xFD, 0x02);
		InsertScript("Scripts/[Ys3]-Script06.txt", argv[3], argv[2], PTR_06, LastPos, 0x8000, 0xFD, 0x01);
	    InsertScript("Scripts/[Ys3]-Script07.txt", argv[3], argv[2], PTR_07, LastPos, 0x8000, 0xFF, 0x18);
		InsertScript("Scripts/[Ys3]-Script08.txt", argv[3], argv[2], PTR_08, LastPos, 0x8000, 0xFD, 0x01);
		InsertScript("Scripts/[Ys3]-Script09.txt", argv[3], argv[2], PTR_09, LastPos, 0x8000, 0xFD, 0x01);
		InsertScript("Scripts/[Ys3]-Script10.txt", argv[3], argv[2], PTR_10, LastPos, 0x8000, 0xFD, 0x06);
		InsertScript("Scripts/[Ys3]-Script11.txt", argv[3], argv[2], PTR_11, LastPos, 0x8000, 0xFD, 0x01);
		InsertScript("Scripts/[Ys3]-Script12.txt", argv[3], argv[2], PTR_12, LastPos, 0x8000, 0x00, 0x04);
		InsertScript("Scripts/[Ys3]-Script13.txt", argv[3], argv[2], PTR_13, LastPos, 0x8000, 0xFD, 0x29);
		InsertScript("Scripts/[Ys3]-Script14.txt", argv[3], argv[2], PTR_14, LastPos, 0x8000, 0xFD, 0x30);
		InsertScript("Scripts/[Ys3]-Script15.txt", argv[3], argv[2], PTR_15, LastPos, 0x8000, 0xFD, 0x07);
		InsertScript("Scripts/[Ys3]-Script16.txt", argv[3], argv[2], PTR_16, LastPos, 0x8000, 0xFD, 0x01);
		InsertScript("Scripts/[Ys3]-Script17.txt", argv[3], argv[2], PTR_17, LastPos, 0x8000, 0xFD, 0x01);
		InsertScript("Scripts/[Ys3]-Script18.txt", argv[3], argv[2], PTR_18, LastPos, 0x8000, 0xFD, 0x01);
		InsertScript("Scripts/[Ys3]-Script19.txt", argv[3], argv[2], PTR_19, LastPos, 0x8000, 0xFD, 0x01);
		//
		//
		InsertScript("Scripts/[Ys3]-Text-01.txt", argv[3], argv[2],  PTR_START01, 0x28418, 0x00, 0x00, 0x128);
		InsertScript("Scripts/[Ys3]-Text-02.txt", argv[3], argv[2],  PTR_START02, LastPos, 0x00, 0x00, 0x30);
		InsertScript("Scripts/[Ys3]-Text-03.txt", argv[3], argv[2],  PTR_START03, LastPos, 0x00, 0x00, 0x50);
		InsertScript("Scripts/[Ys3]-MteTable.txt", "Tabelas/Ys3-Static-Pt.tbl", argv[2], PTR_MTE,     LastPos, 0x00, 0x00, 0x1e);

	}
	else
	{
		printf("Opcao \'%s\' invalida.\n", argv[1]);
		printf("Uso: Ys3-Main -[d|i|dm|im] <Nome Da Rom> <Tbl>\n");
		return 0;		
	}

	return 0;
}
